/**
	通过id获取DOM节点
*/
function $(id){
	return document.getElementById(id);
}
/**
	生成新的元素
*/
function createHtml(lable){
	return document.createElement(lable);
}
/**
	获取目标时间跟当前的差距函数
*/
function gettime(iNum){
	var 
		iDay     = null,
		iHour    = null,
		iMinnute = null,
		iSecond  = null, 
		iLength  = null,
		sTime    = '',
		oTime    = $('time');
	var iDate = new Date().getTime(); //获取当前时间
	iLength = Math.abs(iDate - iNum); //获取时间之间的差距

	iDay     = parseInt(iLength / (1000 * 24 * 60 * 60)); //计算天数
	iHour    = parseInt((iLength - (iDay * 1000 * 24 * 60 * 60)) / (1000 * 60 * 60)); //计算小时
	iMinnute = parseInt((iLength - (iDay * 1000 * 24 * 60 * 60) - (iHour * 1000 * 60 * 60)) / (1000 * 60 ));//计算分钟
	iSecond  = parseInt((iLength - (iDay * 1000 * 24 * 60 * 60) - (iHour * 1000 * 60 * 60) - (iMinnute * 1000 * 60)) / 1000);//计算分钟
	if(iHour < 10){
		iHour = '0'+iHour;
	}
	if(iMinnute < 10){
		iMinnute = '0'+iMinnute;
	}
	if(iSecond < 10){
		iSecond = '0'+iSecond;
	}
	sTime += '距离今天' + iDay +'天' + iHour + '时' + iMinnute + '分' + iSecond + 's';
	return oTime.innerHTML = sTime;
}
//判断碰撞
function pz(obj1,obj2){
	var 
		iH1 = obj1.offsetHeight,
		iW1 = obj1.offsetWidth,
		iL1 = obj1.offsetLeft,
		iT1 = obj1.offsetTop,
		iH2 = obj2.offsetHeight,
		iW2 = obj2.offsetWidth,
		iL2 = obj2.offsetLeft,
		iT2 = obj2.offsetTop;

	if(iW1 + iL1 <= iL2 || iT1 + iH1 <= iT2 || iL2 + iW2 <= iL1 || iT2 + iH2 <= iT1) {
		return false;
	} else {
		return true;
	}
}
/**
	找到数组中最大值
*/
function findmax(arr){
	var iMax = arr[0]; //假设第一个是最大值
	arr.forEach(function(v){
		if (iMax < v) {
			iMax = v;
		}
	})
	return iMax;
}
//缓慢运动
function bufferMove(obj, oTarget, fn){
	clearInterval(obj.oTimer);
	obj.oTimer = setInterval(function () {
		// 假设所有的属性均已运动完毕
		var bBtn = true;
		// 遍历对象
		for(var sAttr in oTarget) {
			// 获取当前值
			if(sAttr === 'opacity') {
				var iCur = parseInt(getStyle(obj, sAttr) * 100);
			} else {
				var iCur = parseInt(getStyle(obj, sAttr));
			}
			// 计算速度
			var iSpeed = (oTarget[sAttr] - iCur) / 8;
			iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

			// 开始赋值
			var iNext = iCur + iSpeed;
			if(sAttr === 'opacity') {
				obj.style.opacity = iNext / 100;
				obj.style.filter = 'alpha(opacity=' + iNext + ')';
			} else {
				obj.style[sAttr] = iNext + 'px';
			}

			// 检测当前属性是否真的已经运动完毕
			if(iNext !== oTarget[sAttr]) {
				bBtn = false;
			}
		}

		if(bBtn) {
			clearInterval(obj.oTimer);
			fn && fn();
		}
	}, 50);
}
//获取任意属性属性值
function getStyle(obj, sAttr) {
	if(obj.currentStyle) {
		return obj.currentStyle[sAttr];
	} else {
		return getComputedStyle(obj, false)[sAttr];
	}
}


